package com.antis.olsl.magic.adapter;

import android.graphics.Color;
import android.text.TextUtils;

import com.antis.olsl.library.widget.CircleProgressBar;
import com.antis.olsl.magic.R;
import com.antis.olsl.magic.response.GetTopAnalysisTotalResp;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

import timber.log.Timber;

public class Top60ItemAdapter extends BaseQuickAdapter<GetTopAnalysisTotalResp.ContentBean, BaseViewHolder> {
    public Top60ItemAdapter(int layoutResId, List<GetTopAnalysisTotalResp.ContentBean> data) {
        super(layoutResId, data);

        addChildClickViewIds(R.id.layout_title);
    }

    @Override
    protected void convert(BaseViewHolder helper, GetTopAnalysisTotalResp.ContentBean item) {
        if (!TextUtils.isEmpty(item.itemName)) {
            helper.setText(R.id.text_label, item.itemName);
        }
        CircleProgressBar circleProgressBar = helper.getView(R.id.circle_progress_bar);
        float overlapRate = 0;
        if (!TextUtils.isEmpty(item.overlapRate)) {
            try {
                overlapRate = Float.parseFloat(item.overlapRate);
            } catch (NumberFormatException e) {
                Timber.tag("hhh").e("NumberFormatException");
            }
        }
        Timber.tag("hhh").e("overlapRate= " + overlapRate);

        if (!TextUtils.isEmpty(item.type)) {
            switch (item.type) {
                case "数量金额Top60重叠":
                    circleProgressBar.setProgressStartColor(Color.parseColor("#F14545"));
                    circleProgressBar.setProgressEndColor(Color.parseColor("#FF8888"));
                    break;
                case "金额利润Top60重叠":
                case "金额Top60":
                case "数量Top60":
                case "毛利Top60":
                    circleProgressBar.setProgressStartColor(Color.parseColor("#5C6AFA"));
                    circleProgressBar.setProgressEndColor(Color.parseColor("#4C9DF5"));
                    break;
                case "数量利润Top60重叠":
                case "数量金额毛利Top60":
                    circleProgressBar.setProgressStartColor(Color.parseColor("#09B0C5"));
                    circleProgressBar.setProgressEndColor(Color.parseColor("#1DC089"));
                    break;
                default:
                    break;
            }
        }

        circleProgressBar.setProgress(overlapRate, item.itemType);

        String strOverlapRate = "";
        if (!TextUtils.isEmpty(item.overlapRate)) {
            strOverlapRate = item.overlapRate.concat("%");
        }
        helper.setText(R.id.text_overlap_rate, strOverlapRate);

        String skuProportion = "";
        if (!TextUtils.isEmpty(item.skuProportion)) {
            skuProportion = item.skuProportion.concat("%");
        }
        helper.setText(R.id.text_sku_proportion, skuProportion);
        if (!TextUtils.isEmpty(item.salesVolume)) {
            helper.setText(R.id.text_sales_volume, item.salesVolume);
        }
        if (!TextUtils.isEmpty(item.salesAmount)) {
            helper.setText(R.id.text_sales_amount, item.salesAmount);
        }
    }
}
